<div class="modal-header">
  <button type="button" class="close" data-dismiss="modal" aria-label="关闭"><span aria-hidden="true">&times;</span></button>
  <h4 class="modal-title" id="extension-modal-label">图片上传</h4>
</div>
<div class="modal-body editor-body-sm">
	<div class="widget-avatar">
		<span id="swfcontainer">本组件需要安装Flash Player后才可使用，请从<a href="http://www.adobe.com/go/getflashplayer">这里</a>下载安装。</span>
	</div>
	<button type="button" id="upload" class="hidden"></button>
</div>

<script type="text/javascript">
<!--
	// 销毁上传组件
	function destroyPictures(){
		jQuery(".widget-avatar").html('<span id="swfcontainer"></span>');	
	}
	
	// 图片上传组件
	function createPictures(trigger){
		var _input = jQuery(trigger).prev(":hidden[name='pictures']");
		var _image = jQuery("img",trigger);
		var _datas = jQuery(trigger).data();
				
		if(jQuery("#swf").length == 0){
			var swf_fullAvatarEditor = "/miwawa/resources/lib/miwawa/1.0.2/js/plugins/avatar/fullAvatarEditor.swf";
			var swf_expressInstall = "/miwawa/resources/lib/miwawa/1.0.2/js/plugins/avatar/expressInstall.swf";
			var url = "/miwawa/{dbname}/file/avatar?group=article".replace("{dbname}", dbname);
			require(['avatar'],function(avatar){
				 swfobject.addDomLoadEvent(function(){
						var swf = new fullAvatarEditor(swf_fullAvatarEditor, swf_expressInstall, "swfcontainer", {
							id: 'swf',
							tab_visible: false,
							method: 'post',
							upload_url: url,	
							src_url: "",
							src_upload: 1,
							avatar_sizes: '300*150',
							avatar_intro: '截取图片如下：',
							avatar_sizes_desc: '300*150像素'
						}, function(result){
							if (result.code == 5){
								switch(result.type){
			            case 0: callback(result.content.avatarUrls[0]); break;
			            case 1: jQuery.message.warning("图片文件未找到！"); break;
			            default: jQuery.message.warning("图片上传失败！"); break;
				        }
							}
						});
						document.getElementById("upload").onclick=function(){
							swf.call("upload");
						};
				 });
			});
		}
		
		function callback(avatarUrl){
			// 编辑模式下，更新图片
			if(_datas.update){
	 			jQuery.ajaxsend({
					url:"/miwawa/{dbname}/common/update".replace("{dbname}",dbname),
					data:{
						"entityClass":_datas.entity,
						"bean":{
							"id":_datas.pk,
							"avatar":avatarUrl
						}
					}
				});
	 		}
			
			_input.val(avatarUrl);
			_image.attr("src", avatarUrl);
	 		jQuery("#extension-modal").modal("hide");
		}
	}
//-->
</script>